package com.example.myapplication11;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button startService=(Button) findViewById(R.id.start_service);
        Button stopService=(Button) findViewById(R.id.stop_service);
        Button exitService=(Button) findViewById(R.id.exit_service);

        startService.setOnClickListener(this);
        stopService.setOnClickListener(this);
        exitService.setOnClickListener(this);
    }
    public void onClick(View v){
        switch (v.getId()){
            case R.id.start_service:
                Intent startIntent = new Intent(getApplicationContext(),MyService2.class);
                startService(startIntent);
                break;
            case R.id.stop_service:
                Intent stopIntent = new Intent(getApplicationContext(),MyService2.class);
                stopService(stopIntent);
                break;
            case R.id.exit_service:
                Intent exitIntent = new Intent(getApplicationContext(),MyService2.class);
                stopService(exitIntent);
                finish();
            default:
                break;
        }
    }
}